<template>
	<view class="content">
		<u-cell-group>
			<u-cell :value="item.deal_text" v-for="item in budrecyclelist" :key="item.id">
				<view slot="title" class="u-slot-title">
					<view style="">
						{{item.nickname}}
					</view>
				</view>
				<view slot="label" class="u-slot-label">
					<view style="color:#909193">
						客户来源：{{item.source.name ? item.source.name : '未知'}}
					</view>
					<view class="btn">
						<u-button type="primary" :customStyle="btnStyle" size="mini" text="还原"
							@click="getrecoverydata(item,'warning')"></u-button>
						<u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
							@click="getdeldata(item,'error')">
						</u-button>
					</view>
				</view>
			</u-cell>
		</u-cell-group>
		<u-modal :show="show" :content='content' :showCancelButton="true" @confirm="confirm"
			@cancel="show = false"></u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					width: '10%',
					display: "inline-block",
					marginRight: '5px',
					marginTop: '10px',
					lineHeight: '20px'
				},
				budrecyclelist: [],
				LoginUser: {},
				show: false,
				content: '确认是否删除当前用户?',
				id: 0,
				// error: 表示是调用删除确认框， warning：表示是调用申请确认框
				status: 'error'
			}
		},
		onLoad() {
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.$u.auth.check()
			this.getbudrecycledata()
		},
		methods: {
			async getbudrecycledata() {
				let result = await this.$u.api.business.budrecyclelist()
				if (result.code == 1) {
					this.budrecyclelist = result.data
				}
			},
			getdeldata(val, status) {
				this.content = '确认是否删除“' + val.nickname + "”用户?"
				this.show = true
				this.id = val.id
				this.status = status
			},
			getrecoverydata(val, status) {
				this.status = status
				this.content = '确认是否还原“' + val.nickname + "”用户?"
				this.show = true
				this.id = val.id
			},
			async confirm() {
				this.show = false
				var result = {}
				if (this.status == "error") {
					result = await this.$u.api.business.budrecycledel({
						id: this.id
					})
				} else {
					let data = {
						id: this.id
					}
					result = await this.$u.api.business.budrecyclered(data)
				}
				if (result.code == 1) {
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
					})
					this.getbudrecycledata()
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
		}
	}
</script>

<style>
	.content {
		height: 100vh;
	}

	.btn {}
</style>